<template>
	<view>
		<view class="updateTime">{{item.updateTime?item.updateTime:item.createTime}}</view>
		<view class="updateTime">{{item.nickName}}</view>
		<view class="toolBox">
			<button class="see"  @click="see()">查看</button>
			<button class="edit" v-if="item.del" @click="edit()">编辑</button>
			<button class="delete" v-if="item.isAdmin"  @click="deleteItem()">删除</button>
		</view>
	</view>
</template>

<script>
	import {
		deleteDoc
	} from '../api/byfz';
	export default {
		name: "bottomButton",
		props: {
			item: {
				default: {}
			},
			code: {
				defaulr: ''
			}
		},
		data() {
			return {};
		},
		methods: {
			see() {
				uni.setStorageSync('formData', {
					type: 'see',
					form: this.item
				})
				uni.navigateTo({
					url: '/pages/add/' + this.code
				})
			},
			edit() {
				uni.setStorageSync('formData', {
					type: 'edit',
					form: this.item
				})
				uni.navigateTo({
					url: '/pages/add/' + this.code
				})
			},
			async deleteItem() {
				uni.showModal({
					title: '是否删除该记录?',
					success: async (res) => {
						if (res.confirm) {
							console.log("item==", this.item);
							await deleteDoc(this.item.id)
							this.$emit("success")
							uni.showToast({
								title: '删除成功！',
								icon: 'none'
							})
						} else if (res.cancel) {}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.toolBox {
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		display: flex;
		justify-content: flex-end;

		.see {
			font-size: 25rpx;
			padding: 10rpx 25rpx;
			background-color: rgb(0, 151, 216);
			color: #fff;
		}

		.edit {
			font-size: 25rpx;
			padding: 10rpx 25rpx;
			background-color: #4aac94;
			color: #fff;
		}

		.delete {
			font-size: 25rpx;
			padding: 10rpx 25rpx;
			background-color: red;
			color: #fff;
		}

		uni-button {
			line-height: 1.2 !important;
			margin-left: 10rpx;
			margin-right: 0;
		}
	}

</style>